package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobData() {
        List<Map<String, Object>> jobDataList = empMapper.empJobDataMap();
        List<String> jobList = jobDataList.stream().
                map(map -> map.get("pos").toString())
                .collect(Collectors.toList());
        List<Integer> dataList = jobDataList.stream().
                map(map -> Integer.parseInt(map.get("total").toString()))
                .collect(Collectors.toList());

        JobOption jobOption = new JobOption();
        jobOption.setJobList(jobList);
        jobOption.setDataList(dataList);
        return jobOption;
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.getEmpGenderData();
    }

    @Override
    public ClazzOption getStudentCountData() {
        List<Map<String, Object>> clazzDataList = studentMapper.studentClazzDataMap();
        List<String> clazzList = clazzDataList.stream().
                map(map -> map.get("clazzName").toString())
                .collect(Collectors.toList());
        List<Integer> dataList = clazzDataList.stream().
                map(map -> Optional.ofNullable(map.get("studentNum")).map(studentNum -> Integer.parseInt(studentNum.toString())).orElse(0))
                .collect(Collectors.toList());

        ClazzOption clazzOption = new ClazzOption();
        clazzOption.setClazzList(clazzList);
        clazzOption.setDataList(dataList);
        return clazzOption;
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }


}
